#pragma once

#include <memory>

#include "protocol.hpp"

class NetCal
{
public:
    NetCal()
    {

    }

    ~NetCal()
    {

    }

    std::shared_ptr<Response> calculator(std::shared_ptr<Request> req)
    {
        auto resp = Factory::buildResponse();
        switch (req->getoper())
        {
        case '+':
            resp->_result = req->getx() + req->gety();
            break;
        case '-':
            resp->_result = req->getx() - req->gety();
            break;
        case '*':
            resp->_result = req->getx() * req->gety();
            break;
        case '/':
            {
                if (req->gety() == 0)
                {
                    resp->_code = 1;
                    resp->_desc = "div zero!";
                }
                else
                    resp->_result = req->getx() / req->gety();
            }
            break;
        case '%':
            {
                if (req->gety() == 0)
                {
                    resp->_code = 2;
                    resp->_desc = "mod zero!";
                }
                else
                    resp->_result = req->getx() % req->gety();
            }
            break;
        default:
            {
                resp->_code = 3;
                resp->_desc = "illegal operation";
            }
            break;
        }
        return resp;
    }
};

